<template>
  <div class="goods-root">
    <i class="iconfont icon-guanbi close" @click="closeModal()"></i>
    <div class="goods-title">
      <img
        :src="(active.img === undefined || active.img === '')? defaultImg : active.img"
        class="goods-title-img"
      />
      <div class="goods-title-value">
        <p>{{active.title === '' ? '请选择项目' : active.title}}</p>
        <p class="goods-title-value-price">{{active.price === '' ? '': '￥ ' + active.price}}</p>
      </div>
    </div>
    <div class="goods-content">
      <div
        :class="'goods-content-item ' + good.active"
        @click="selectItem(good,index)"
        v-for="(good,index) in goodsArr"
        :key="index"
      >{{good.title}}</div>
    </div>
  </div>
</template>

<script>
export default {
  props() {
    return {}
  },
  data() {
    return {
      defaultImg: '/static/images/unknown.png',
      active: {
        title: '',
        img: '',
        price: ''
      },
      goodsArr: [
        {title: "按摩椅", active: 'active', img: 'https://erp.0511mzone.com/upload/2020-7-8/upload743549714.jpg', price: 30}
      ]
    }
  },
  mounted() {
    if (this.goodsArr.length > 0) {
      this.active = this.goodsArr[0];
    }
  },
  methods: {
    closeModal() {
      this.$parent.canelGoodsSelect();
    },
    selectItem(good, index) {
      if (good.active === 'active') {
        good.active = '';
        this.active = {
          title: '',
          img: '',
          price: ''
        }
      } else {
        this.goodsArr.forEach(item => {
          item.active = '';
        });
        good.active = 'active'
        this.active = good;
      }
    }
  }
}
</script>
<style scoped lang="less">
.goods-root {
  z-index: 1001;
  padding: 10px;
  background-color: #ffffff;
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  box-sizing: border-box;
  border-radius: 3% 3% 0 0;
  .close {
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 20px;
  }
  .goods-title {
    font-size: 16px;
    padding: 5px 0;
    border-bottom: 2rpx solid #f3f3f3;
    .goods-title-img {
      height: 50px;
      width: 50px;
      padding: 5px;
      vertical-align: middle;
    }
    .goods-title-value {
      display: inline-block;
      padding: 0px 15px;
      p {
        padding: 5px 0;
      }
      .goods-title-value-price {
        color: rgb(255, 117, 117);
        font-size: 14px;
      }
    }
  }
  .goods-content {
    height: 150px;
    padding: 10px 0;
    font-size: 13px;
    .goods-content-item {
      padding: 9px;
      float: left;
      margin: 8px;
      border-radius: 13%;
      background-color: #f3f3f3;
      border: 1px solid #f3f3f3;
    }
    .active {
      color: rgb(255, 117, 117);
      border: 1px solid rgb(255, 117, 117);
      background-color: rgb(255, 238, 238);
    }
  }
}
</style>